package com.weijian.controller.admin;

import com.weijian.common.pojo.CommonResult;
import com.weijian.constants.RedisConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@Schema(description = "管理员店铺相关接口")
@RequestMapping("/admin/shop")
@RequiredArgsConstructor
public class ShopController {

    final StringRedisTemplate redisTemplate;

    @PutMapping("/{status}")
    @Schema(description = "设置店铺营业状态")
    public CommonResult<String> setStatus(@PathVariable Integer status) {
        log.info("设置店铺营业状态为:{}", status == 1 ? "营业中" : "打烊中");
        String key = RedisConstants.CACHE_SHOP_STATUS;
        redisTemplate.opsForValue().set(key, String.valueOf(status));
        return CommonResult.success("成功");
    }

    @GetMapping("/status")
    @Schema(description = "查询店铺营业状态")
    public CommonResult<Integer> queryStatus() {
        String key = RedisConstants.CACHE_SHOP_STATUS;
        Integer status = Integer.valueOf(redisTemplate.opsForValue().get(key));
        log.info("店铺状态为:{}", status == 1 ? "营业中" : "打烊中");
        return CommonResult.success(status);
    }

}